```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka 消息持久化机制详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #7c3aed;
        }
        .highlight {
            background-color: rgba(124, 58, 237, 0.1);
            padding: 0.2em 0.4em;
            border-radius: 4px;
            font-weight: 500;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin: 0.1em 0.2em 0 0;
            color: #7c3aed;
            font-weight: bold;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col items-center text-center">
                <span class="inline-block px-3 py-1 text-xs font-semibold bg-white text-indigo-600 rounded-full mb-4">分布式系统</span>
                <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Kafka 消息持久化机制深度解析</h1>
                <p class="text-xl md:text-2xl max-w-3xl opacity-90 mb-8">探索 Kafka 如何通过创新的存储架构实现高性能、高可靠的消息传递</p>
                <div class="flex space-x-4">
                    <a href="#overview" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-opacity-90 transition duration-300">
                        <i class="fas fa-book-open mr-2"></i>开始阅读
                    </a>
                    <a href="#summary" class="px-6 py-3 text-white font-medium border border-white rounded-lg hover:bg-white hover:bg-opacity-10 transition duration-300">
                        <i class="fas fa-list-ul mr-2"></i>核心概念
                    </a>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">Kafka 消息持久化概述</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <p class="text-lg drop-cap mb-6">Kafka 的持久化机制基于磁盘文件系统，将消息写入分区的日志文件中。Kafka 通过将每个 <span class="highlight">Topic</span> 划分为多个 <span class="highlight">Partition</span>，每个 <span class="highlight">Partition</span> 由多个 <span class="highlight">Segment</span> 组成。Kafka 使用文件系统中的日志文件来保证高效的存储与读取。</p>
                    
                    <div class="grid md:grid-cols-2 gap-8 mt-10">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-pen-fancy text-indigo-500 mr-3"></i>消息写入流程
                            </h3>
                            <p class="text-gray-700">消息生产者将消息发送到指定的分区，Kafka 接收消息后，会将其追加到该分区对应的日志文件中。日志文件使用 <span class="highlight">Segment</span> 来管理，每个 <span class="highlight">Segment</span> 文件最多可以存储固定大小的消息数据。</p>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-project-diagram text-indigo-500 mr-3"></i>核心组件关系
                            </h3>
                            <div class="mermaid">
                                graph LR
                                    A[Topic] --> B[Partition 1]
                                    A --> C[Partition 2]
                                    A --> D[Partition 3]
                                    B --> E[Segment 1]
                                    B --> F[Segment 2]
                                    E --> G[消息1]
                                    E --> H[消息2]
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Partition & Log Design -->
        <section id="partition-design" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">分区与日志文件的设计</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-cubes text-indigo-500 mr-3"></i>分区与段结构
                        </h3>
                        <p class="text-gray-700 mb-6">Kafka 将每个 <span class="highlight">Topic</span> 划分为多个 <span class="highlight">Partition</span>，每个 Partition 存储一系列的日志文件。日志文件以 <span class="highlight">Segment</span> 为单位，每个 Segment 文件都有一个固定的最大大小，达到最大值后会创建一个新的 Segment 文件。</p>
                        <p class="text-gray-700">这样，Kafka 能够有效地管理磁盘空间，并且通过顺序写入提高了磁盘 I/O 的性能。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-code text-indigo-500 mr-3"></i>代码示例
                        </h3>
                        <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                            <pre>// 主要的写入日志的过程，下面是消息写入到 Segment 文件的部分
File logFile = new File(segmentFilePath);
RandomAccessFile randomAccessFile = new RandomAccessFile(logFile, "rw");
logFileChannel = randomAccessFile.getChannel();

// 这里是将消息追加到文件的尾部
logFileChannel.write(ByteBuffer.wrap(messageBytes));</pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <h3 class="text-xl font-semibold mb-4">性能优化</h3>
                    <p class="text-gray-700 mb-6">Kafka 在写入消息时，会不断地将消息追加到日志文件的尾部。通过顺序写入，Kafka 能够提高磁盘 I/O 的效率，减少磁盘寻址的开销。</p>
                    
                    <div class="flex flex-wrap justify-center gap-8 mt-6">
                        <div class="text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-bolt text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold">顺序写入</h4>
                            <p class="text-sm text-gray-600">减少磁盘寻址</p>
                        </div>
                        <div class="text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-layer-group text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold">分段存储</h4>
                            <p class="text-sm text-gray-600">高效管理空间</p>
                        </div>
                        <div class="text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-3">
                                <i class="fas fa-memory text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold">高效缓存</h4>
                            <p class="text-sm text-gray-600">优化性能</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Filesystem & Sync -->
        <section id="filesystem-sync" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">文件系统的写入和同步</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-hard-drive text-indigo-500 mr-3"></i>写入机制
                            </h3>
                            <p class="text-gray-700 mb-4">Kafka 在持久化消息时，通过使用 <span class="highlight">操作系统的内存映射文件</span> 和 <span class="highlight">直接内存</span> 来进行高效的文件写入。这样做的好处是减少了内存和磁盘之间的复制过程，从而提升了写入性能。</p>
                            <p class="text-gray-700">Kafka 通过异步写入来减少阻塞，默认情况下，Kafka 的生产者不会等待文件系统的同步确认。Kafka 将消息先缓存到 <span class="highlight">内存中</span>，然后周期性地将内存中的数据写入磁盘。</p>
                        </div>
                        <div>
                            <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto h-full">
                                <pre>// 使用内存映射文件提升性能
MappedByteBuffer buffer = logFileChannel.map(
    FileChannel.MapMode.READ_WRITE, 
    position, 
    size
);
buffer.put(messageBytes);</pre>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 p-6 bg-indigo-50 rounded-lg">
                        <h4 class="font-semibold text-indigo-700 mb-3 flex items-center">
                            <i class="fas fa-info-circle mr-2"></i>同步刷盘机制
                        </h4>
                        <p class="text-gray-700">在某些情况下，Kafka 会通过 <span class="highlight">同步刷盘</span>（fsync）来保证消息已经被写入磁盘，以确保数据的可靠性。这种同步操作会在后台线程中执行，减少了主线程的阻塞。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Log Compaction -->
        <section id="log-compaction" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">Kafka 日志压缩与日志段合并</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-compress-alt text-indigo-500 mr-3"></i>日志压缩机制
                        </h3>
                        <p class="text-gray-700 mb-6">Kafka 支持 <span class="highlight">日志压缩</span>（Log Compaction）机制，以优化存储。日志压缩的过程是 Kafka 删除已处理的消息并保留最新的消息。Kafka 会定期检查日志文件，并删除不再需要的历史消息。</p>
                        <p class="text-gray-700">这一机制有助于减少存储空间的占用，并提升 Kafka 在处理大规模数据时的存储效率。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-code text-indigo-500 mr-3"></i>压缩实现
                        </h3>
                        <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                            <pre>// 日志压缩机制会将相同键的消息合并
public void compactLog() {
    // 对日志文件进行合并和压缩
    for (LogSegment segment : segments) {
        segment.compact();
    }
}</pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8 items-center">
                        <div>
                            <h3 class="text-xl font-semibold mb-4">压缩效果可视化</h3>
                            <div class="mermaid">
                                graph LR
                                    A[原始日志] -->|压缩前| B[消息1 v1]
                                    A --> C[消息1 v2]
                                    A --> D[消息1 v3]
                                    A --> E[消息2 v1]
                                    A --> F[消息3 v1]
                                    A -->|压缩后| G[消息1 v3]
                                    A --> H[消息2 v1]
                                    A --> I[消息3 v1]
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-3">压缩优势</h4>
                            <ul class="space-y-3 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>减少存储空间占用</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>提高数据读取效率</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>保持最新数据状态</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>优化备份和恢复性能</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Segment Management -->
        <section id="segment-mgmt" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">Segment 文件与日志段管理</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-file-alt text-indigo-500 mr-3"></i>Segment 文件管理
                            </h3>
                            <p class="text-gray-700 mb-4">Kafka 使用 <span class="highlight">Segment</span> 文件来存储分区内的消息。每个 <span class="highlight">Segment</span> 文件对应一个特定的磁盘文件，消息在写入时会被追加到该文件的尾部。</p>
                            <p class="text-gray-700">当一个 Segment 文件达到预定的大小限制时，Kafka 会关闭当前文件并创建一个新的 Segment 文件。</p>
                        </div>
                        <div>
                            <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                                <pre>// 每个 Segment 文件有最大大小限制，达到限制时创建新的文件
if (currentSegment.size() >= maxSegmentSize) {
    currentSegment.close();
    currentSegment = createNewSegment();
}</pre>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8">
                        <h4 class="font-semibold text-lg mb-4 flex items-center">
                            <i class="fas fa-cog text-indigo-500 mr-3"></i>Segment 生命周期管理
                        </h4>
                        <div class="mermaid">
                            sequenceDiagram
                                participant Producer
                                participant Kafka
                                participant Disk
                                
                                Producer->>Kafka: 发送消息
                                Kafka->>Disk: 追加到当前Segment
                                alt Segment达到最大大小
                                    Kafka->>Kafka: 关闭当前Segment
                                    Kafka->>Disk: 创建新Segment
                                end
                                Kafka->>Producer: 确认消息接收
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Message Indexing -->
        <section id="message-indexing" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">消息的索引与随机访问</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-search text-indigo-500 mr-3"></i>索引机制
                            </h3>
                            <p class="text-gray-700 mb-4">为了实现高效的消息检索，Kafka 会为每个 Partition 维护一个 <span class="highlight">索引文件</span>，索引文件记录了消息的偏移量和对应的文件位置。</p>
                            <p class="text-gray-700">每次消费者拉取消息时，Kafka 可以通过索引文件快速定位消息的位置，避免全盘扫描。</p>
                        </div>
                        <div>
                            <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                                <pre>// 索引文件记录了消息偏移量与位置
public class LogSegment {
    private final Map&lt;Long, Long&gt; indexMap = new HashMap&lt;&gt;();

    public long getMessagePosition(long offset) {
        return indexMap.get(offset);
    }
}</pre>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 p-6 bg-indigo-50 rounded-lg">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 text-indigo-600">
                                <i class="fas fa-lightbulb text-2xl"></i>
                            </div>
                            <div class="ml-4">
                                <h4 class="font-semibold text-indigo-700 mb-2">索引优化</h4>
                                <p class="text-gray-700">Kafka 的索引采用了稀疏索引的设计，并不为每条消息都创建索引项，而是每隔一定量的消息建立索引。这种设计在索引大小和查找效率之间取得了良好的平衡。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Producer & Durability -->
        <section id="producer-durability" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">生产者与持久化的关系</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-paper-plane text-indigo-500 mr-3"></i>生产者写入策略
                            </h3>
                            <p class="text-gray-700 mb-4">Kafka 生产者通过向 <span class="highlight">Partition</span> 写入消息来实现数据的持久化。在消息发送过程中，生产者会根据配置的 <span class="highlight">acks</span> 参数来控制消息的可靠性。</p>
                            <p class="text-gray-700">当 <span class="highlight">acks=all</span> 时，Kafka 会等待所有副本确认消息写入磁盘后再返回成功信号。</p>
                        </div>
                        <div>
                            <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                                <pre>// 生产者在写入时根据 acks 参数确定写入确认策略
public void sendMessage(Message message) {
    if (acks == Acks.ALL) {
        // 等待所有副本确认
        awaitReplication(message);
    } else {
        // 异步返回
        sendAsync(message);
    }
}</pre>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8">
                        <h4 class="font-semibold text-lg mb-4">acks 参数对比</h4>
                        <div class="overflow-x-auto">
                            <table class="min-w-full divide-y divide-gray-200">
                                <thead class="bg-gray-50">
                                    <tr>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">acks 值</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">含义</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">可靠性</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">延迟</th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white divide-y divide-gray-200">
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">0</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">不等待确认</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">最低</td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">1</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">等待leader确认</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中等</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中等</td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">all/-1</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">等待所有ISR副本确认</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">最高</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">最高</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Reliability & Consistency -->
        <section id="reliability" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">持久化的可靠性与一致性</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-shield-alt text-indigo-500 mr-3"></i>副本机制
                            </h3>
                            <p class="text-gray-700 mb-4">Kafka 的消息持久化机制通过 <span class="highlight">副本</span> 来保证数据的一致性与高可用性。每个分区的消息会被复制到多个 <span class="highlight">Broker</span> 上，副本同步可以通过 Kafka 的 <span class="highlight">Replication</span> 机制来实现。</p>
                            <p class="text-gray-700">副本之间会根据 <span class="highlight">ISR</span> 列表进行同步。</p>
                        </div>
                        <div>
                            <div class="code-block rounded-lg p-4 text-gray-200 font-mono text-sm overflow-x-auto">
                                <pre>// Kafka 的副本同步机制
public class Replication {
    public void replicateMessage(LogSegment segment) {
        for (Replica replica : replicas) {
            replica.sync(segment);
        }
    }
}</pre>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8">
                        <h4 class="font-semibold text-lg mb-4">副本同步流程</h4>
                        <div class="mermaid">
                            graph TD
                                A[Leader] -->|推送消息| B[Follower 1]
                                A -->|推送消息| C[Follower 2]
                                A -->|推送消息| D[Follower 3]
                                B -->|确认| A
                                C -->|确认| A
                                D -->|确认| A
                                A --> E[更新HW]
                        </div>
                    </div>
                    
                    <div class="mt-8 p-6 bg-indigo-50 rounded-lg">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 text-indigo-600">
                                <i class="fas fa-check-circle text-2xl"></i>
                            </div>
                            <div class="ml-4">
                                <h4 class="font-semibold text-indigo-700 mb-2">高可用性保证</h4>
                                <p class="text-gray-700">通过这种副本机制，即使某些节点发生故障，Kafka 也能保证数据不丢失，并能够继续提供服务。Leader 选举机制确保在 Leader 节点失效时，可以从 ISR 列表中选举出新的 Leader。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section id="summary" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-600 rounded-full"></div>
                <h2 class="ml-4 text-2xl font-bold">核心概念总结</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-file-alt text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">Segment 文件</h3>
                        <p class="text-gray-600 text-sm">Kafka 将消息存储在 Segment 文件中，每个 Segment 有固定大小限制，达到限制后创建新的 Segment。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-search text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">索引机制</h3>
                        <p class="text-gray-600 text-sm">Kafka 维护索引文件记录消息偏移量和位置，实现高效的消息随机访问。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-compress-alt text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">日志压缩</h3>
                        <p class="text-gray-600 text-sm">Kafka 可以压缩日志，只保留每个键的最新值，减少存储空间占用。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-copy text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">副本机制</h3>
                        <p class="text-gray-600 text-sm">消息被复制到多个 Broker 上，通过 ISR 列表保持同步，确保数据不丢失。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-hdd text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">高效存储</h3>
                        <p class="text-gray-600 text-sm">使用顺序写入、内存映射文件等技术优化磁盘 I/O 性能。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-sliders-h text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-lg font-semibold mb-2">生产者控制</h3>
                        <p class="text-gray-600 text-sm">通过 acks 参数控制消息持久化级别，平衡可靠性和性能。</p>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="flex items-center mb-4">
                    <i class="fas fa-book-open text-indigo-400 text-2xl mr-3"></i>
                    <span class="text-xl font-semibold text-white">技术小馆</span>
                </div>
                <div class="mb-6">
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="text-sm text-gray-500">
                    &copy; 2023 技术小馆. All rights reserved.
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: { useMaxWidth: true, htmlLabels: true },
            sequence: { useMaxWidth: true, height: 40 }
        });
    </script>
</body>
</html>
```